package com.sgb.jicai.view.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;

import com.sgb.jicai.R;
import com.sgb.jicai.entity.AttrBean;
import com.sgb.jicai.entity.CentralizedMiningEntity;
import com.swgk.core.BR;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class CentralizedMiningChildAdapter extends BaseRecycleAdapter<CentralizedMiningEntity.GoodsEntity> {

    public CentralizedMiningChildAdapter(Context context, List<CentralizedMiningEntity.GoodsEntity> datas) {
        super(context, R.layout.item_centralized_mining_child, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final CentralizedMiningEntity.GoodsEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView tvparam = holder.itemView.findViewById(R.id.tv_param);
        if (entity.getAttrlist()!=null&&entity.getAttrlist().size()>0){
            StringBuilder stringattr = new StringBuilder();
            for (AttrBean attrBean : entity.getAttrlist()) {
                if (!TextUtils.isEmpty(attrBean.getValue())){
                    stringattr.append(attrBean.getName()).append(":").append(attrBean.getValue()).append(" ");
                }
            }
            if (!TextUtils.isEmpty(stringattr.toString())){
                tvparam.setText(stringattr.toString());
            }else {
                tvparam.setText("无");
            }
        }else {
            tvparam.setText("无");
        }
    }

    @Override
    public int getItemCount() {
        if (getDatas() != null && getDatas().size() > 0) {
            return Math.min(getDatas().size(), 3);
        }
        return 0;
    }
}
